package com.wp.design.create.factorySet.simpleFactory;

/**
 * 简单工厂类
 */
public class SimpleFactory {
	/**
	 * 直接根据类名来获取对象
	 * 优点：避免了新增课堂时，对工厂类的修改
	 * @param c
	 * @return
	 */
	public static Video createVideo(Class c){
		Video t = null;
		try {
			t= (Video) Class.forName(c.getName()).newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} finally {
			return t;
		}
	}

	/**
	 * 根据名称参数来对应生成相应的对象
	 * 缺点：当新增课程时，需要对工厂中的方法进行增加
	 * @param name
	 * @return
	 */
	public static Video createVideo(String name){
		if (name.equalsIgnoreCase("java")){
			return new JavaVideo();
		}else if (name.equalsIgnoreCase("phyton")){
			return new PhytonVideo();
		}
		return null;
	}
}
